<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>发文</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link th:href="@{/res/notice/lib/weui.min.css}" rel="stylesheet"/>
    <link th:href="@{/res/notice/css/jquery-weui.css}" rel="stylesheet"/>
    <link th:href="@{/res/notice/css/font-awesome.css?v=4.4.0}" rel="stylesheet"/>
    <link th:href="@{/res/notice/css/common.css}" rel="stylesheet"/>
</head>
<body class="bgline3">
<form class="form-horizontal m" id="form-notice-add">
    <!--主题-->
    <div class="bgpart mt10">
        <div class="ft16 posRelt pl15 lh40"><label class="weui-label is-required bold">主题 <span
                class="ft12 red">(必填)</span></label>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" name="noticeTheme" type="text" th:field="*{notice.noticeTheme}"
                       placeholder="请输入"
                       required>
            </div>
        </div>
    </div>
    <!--内容-->
    <!--<div class="bgpart mt10">
        <div class="ft16 posRelt pl15 lh40"><label class="weui-label is-required bold">内容 <span class="ft12 red">(必填)</span></label></div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <textarea class="weui-textarea" ame="noticeContent" th:field="*{notice.noticeContent}" placeholder="请输入" rows="3" required></textarea>
            </div>
        </div>
    </div>-->
    <!--附件-->
    <div class="bgpart mt10">
        <div class="plr15 pb10">
            <label class="weui-label bold">附件 <span class="ft12 gray97">(最大50M)</span></label>
            <input name="file" type="hidden" th:value="${file.fileRoute}">
            <input id="williamYe" type="file" class="mt10">
        </div>
    </div>
    <!--署名-->
    <div class="bgpart mt10">
        <div class="ft16 posRelt pl15 lh40 bold"><label class="weui-label">署名</label></div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" name="noticeSignature" type="text" th:field="*{notice.noticeSignature}"
                       placeholder="请输入">
            </div>
        </div>
    </div>
    <!--接收对象-->
    <div class="bgpart mt10">
        <div class="ft16 posRelt pl15 lh40 flex between alcenter">
            <label class="weui-label is-required bold">接收对象 <span class="ft12 red">(必填)</span></label>
            <div class="posRelt overxy" style="top:8px; right: 10px;">
                <a class="weui-btn weui-btn_mini weui-btn_primary bgblue" onclick="checkTree()"><i
                        class="fa fa-user"></i> 选择人员</a>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input id="addresseeName" name="addresseeName" th:value="${addresseeName}" type="hidden">
                <textarea id="realName" class="ft12 gray97" rows="3" type="text"
                          style="width: 250px;margin-right: 20px;"
                          th:value="${realNames}" placeholder="请选择接收对象" ></textarea>
            </div>
        </div>
    </div>
    <!--通知类型-->
    <div class="bgpart mt10">
        <div class="ft16 posRelt pl15 lh40 bold"><label class="weui-label">通知类型</label></div>
        <div class="weui-cells weui-cells_checkbox mt0 ft14">
            <div class="radio-box" style="height: 34px;" th:each="dict : ${@dict.getType('sys_notice_type')}">
                <input type="radio" th:id="${'type_' + dict.id}" name="noticeType" th:value="${dict.itemValue}"
                       th:checked="${dict.isDefault == 'Y' ? true : false}">
                <label th:for="${'type_' + dict.id}" th:text="${dict.itemText}"></label>
            </div>
        </div>
    </div>
    <!--短信-->
    <div class="bgpart mt10">
        <div class="ft16 posRelt pl15 lh40 bold"><label class="weui-label">短信</label></div>
        <div class="weui-cells weui-cells_radio mt0 ft14">
            <div class="radio-box" style="height: 34px;" th:each="dict : ${@dict.getType('sys_notice_message')}">
                <input type="radio" th:id="${'message_' + dict.id}" name="noticeMessage"
                       th:value="${dict.itemValue}"
                       th:checked="${dict.isDefault == 'Y' ? true : false}">
                <label th:for="${'message_' + dict.id}" th:text="${dict.itemText}"></label>
            </div>
        </div>
    </div>
</form>
<div class="plr30 ptb20">
    <a href="javascript:;" class="weui-btn weui-btn_primary" onclick="sendThis()"><i
            class="fa fa-paper-plane-o mr10"></i> 发送</a>
</div>

<script th:src="@{/res/notice/lib/jquery-2.1.4.js}"></script>
<script th:src="@{/res/notice/js/jquery-weui.js}"></script>
<script th:src="@{/res/ajax/libs/layer/layer.min.js}"></script>
<script th:src="@{/res/bonorsoft/js/common.js?v=4.2.0}"></script>
<script th:src="@{/res/bonorsoft/js/william-boot.js}"></script>
<script th:inline="javascript">
    var token = [[${token}]];
    var prefix = "/mobile/notice";

    function sendThis() {
        save(prefix + "/add", $('#form-notice-add').serialize());
    }

    function save(url, data) {
        var config = {
            url: url,
            type: "post",
            dataType: "json",
            data: data,
            beforeSend: function (request) {
                request.setRequestHeader("X-Access-Token", token);
            },
            success: function (result) {
                $.operate.saveSuccess(result);
            }
        };
        $.ajax(config)
    }

    function checkTree() {
        storage.set("token", token);
        var options = {
            title: "选择接收对象",
            width: ($(window).width()),
            height: ($(window).height()),
            url: prefix + "/tree",
            skin: 'layui-layer-gray',
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler(index, layero);
            },
            cancel: function (index) {
                layer.close(index);
            }
        };
        $.modal.openOptions(options);
    }

    function setName(addresseeName, realName) {
        $('#addresseeName').val(addresseeName);
        $('#realName').val(realName);
    }

    function fileUpload(data, $dom) {
        $.ajax({
            url: '/sys/common/upload',
            data: data,
            type: 'POST',
            Accept: 'text/html;charset=UTF-8',
            cache: false,
            contentType:false,
            processData: false,
            beforeSend: function (request) {
                request.setRequestHeader("X-Access-Token",token);
            },
            success: function(res) {
                $($dom).val(res.message);
            },
            error: function(xhr) {
            }
        });
    }

    $('#williamYe').on('change.bs.fileinput ', function (e) {
        // 处理自己的业务
        if (this.files[0]) {
            const formData = new FormData();
            formData.append('file', this.files[0]);
            fileUpload(formData, $('input[name="file"]'));
        } else {
            $('input[name="file"]').val("");
        }
    });

</script>
</body>
</html>
